﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TopNewLib.TopNews
{
    public class SouGouWXTopClass :BaseTop
    {
        public SouGouWXTopClass()
        {
            LinkURL = "http://weixin.sogou.com/";
        }

        public SouGouWXTopClass(string _linkUrl)
        {
            LinkURL = _linkUrl;
        }

        public override List<TopNewItem> GetCurTopNews()
        {
            List<TopNewItem> rs = new List<TopNewItem>();

            string htmlstr = GetHtmlInfo();

            var doc = new HtmlDocument();
            doc.LoadHtml(htmlstr);

            var res = doc.DocumentNode.SelectSingleNode("//*[@id=\"topwords\"]");
            if (res != null)
            {
                var list2 = res.SelectNodes("li/a");//选择标签数组
                var list3 = res.SelectNodes("li/span/span");//选择标签数组
                if (list2.Count > 0 && list2.Count == list3.Count)
                {
                    for (int i = 0; i < list2.Count; i++)
                    {
                        TopNewItem item = new TopNewItem();

                        item.Title = list2[i].InnerText;
                        item.Url = list2[i].Attributes["href"].Value;
                        item.Describe = list3[i].Attributes["style"].Value.Replace("width:","");

                        rs.Add(item);
                    }
                }
            }

            return rs;
        }
    }
}
